//
//  ViewController.m
//  图片浏览器
//
//  Created by song on 15/1/4.
//  Copyright (c) 2015年 song. All rights reserved.
//

#import "ViewController.h"
#import "SJOImage.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.images =[[NSMutableArray alloc] initWithCapacity:0];
    
    [self.images addObject:[[SJOImage alloc]initWithName:@"data" andContent:@"haha1"]];
    [self.images addObject:[[SJOImage alloc]initWithName:@"dep" andContent:@"haha2"]];
    [self.images addObject:[[SJOImage alloc]initWithName:@"do" andContent:@"haha3"]];
    [self.images addObject:[[SJOImage alloc]initWithName:@"soft" andContent:@"haha4"]];
    
    SJOImage *img  = [self.images objectAtIndex:0];
    NSString *name = img.name;
    self.tlable.text =[NSString stringWithFormat:@"%d/%d",1,(int)self.images.count];
    self.clable.text = img.content;
    self.img.image = [UIImage imageNamed:name];
    self.index = 1;
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)click:(id)sender {
    
    UIButton *btn =(UIButton *) sender;
    
    int tag = btn.tag;
    BOOL leftflag =NO;
    BOOL rightflag =NO;
    switch (tag) {
        case 10:
            self.index--;
            if(self.index<1)
            {
                 self.index=1;
                 leftflag=YES;
            }else{
                leftflag =NO;
            }
            
            break;
        case 11:
            
            self.index++;
            if(self.index>self.images.count)
            {
                self.index = self.images.count;
                rightflag =YES;
            }else{
                rightflag =NO;
            }
            
            break;
            
        default:
            break;
    }
    
    self.leftbtn.enabled = !leftflag;
    self.rightbtn.enabled = !rightflag ;
    
    SJOImage *img  = [self.images objectAtIndex:self.index-1];
    NSString *name = img.name;
    self.tlable.text =[NSString stringWithFormat:@"%d/%d",self.index,(int)self.images.count];
    self.clable.text = img.content;
    self.img.image = [UIImage imageNamed:name];
    
}
@end
